Skip to content

创建数据库 - CreateDatabase

函数简介

创建数据库,返回一个数据库对象指针。若文件已存在则返回失败。

接口名称

CreateDatabase

DLL调用

c
long CreateDatabase(long ola, string dbName, string password);

参数说明

参数名类型说明
ola长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
dbName字符串数据库文件路径。
password字符串数据库密码。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
long db = ola.CreateDatabase("data/app.db", "");
if (db != 0) {
    int ret = ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)");
    ola.CloseDatabase(db);
}
csharp
using OLAPlug;

var ola = new OLAPlugServer();
long db = ola.CreateDatabase("data/app.db", "");
if (db != 0)
{
    int ret = ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)");
    ola.CloseDatabase(db);
}
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
db = ola.CreateDatabase("data/app.db", "")
if db != 0:
    ret = ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)")
    ola.CloseDatabase(db)
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
long db = ola.CreateDatabase("data/app.db", "");
if (db != 0) {
    ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)");
    ola.CloseDatabase(db);
}
cpp
var ola = com("OlaPlug.OlaSoft")
var db = ola.CreateDatabase("data/app.db", "")
if(db) {
    ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)");
    ola.CloseDatabase(db)
}
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
db = ola.CreateDatabase("data/app.db", "")
If db <> 0 Then
    ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)");
    ola.CloseDatabase(db)
End If
text
.局部变量 ola, OLAPlug
ola.创建 ()
db = ola.CreateDatabase (“data/app.db“, ““)
.如果真 (db ≠ 0)
    ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)");
    ola.CloseDatabase (db)
.如果真结束
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var db = ola.CreateDatabase("data/app.db", "");
if(db){
    ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)");
    ola.CloseDatabase(db);
}
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 db = ola.CreateDatabase("data/app.db", "")
如果真 (db ≠ 0)
{
    ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)");
    ola.CloseDatabase(db)
}
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
long db = ola.CreateDatabase("data/app.db", "");
if (db != 0) {
    ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)");
    ola.CloseDatabase(db);
}

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
long db = CreateDatabase(instance, "data/app.db", "");
if (db != 0) {
    int ret = ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)");
    CloseDatabase(instance, db);
}
csharp
using System.Runtime.InteropServices;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();

long instance = CreateCOLAPlugInterFace();
long db = CreateDatabase(instance, "data/app.db", "");
if (db != 0)
{
    int ret = ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)");
    CloseDatabase(instance, db);
}
python
from ctypes import CDLL, c_int, c_int64

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
db = ola.CreateDatabase(instance, b"data/app.db", b"")
if db:
    ret = ola.ExecuteSql(db, "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT, score REAL)")
    ola.CloseDatabase(instance, db)

返回值

数据库对象指针。若创建失败,返回 0。